using System;
using System.Configuration;
using Common.Unity.Configuration;
using Common.Unity.Extensions.Configuration;
using Common.Unity.Extensions.PropertyMapper.Policies;
using Microsoft.Practices.ObjectBuilder2;
using Microsoft.Practices.Unity;

namespace Common.Unity.Extensions.PropertyMapper
{
	class PropertyMappingMirroredPolicyReferenceElement : PropertyMappingPolicyReferenceElement
	{
		public override InjectionMember CreateInjectionMember()
		{
			IBuilderPolicy policy = CreatePolicy();
			IMirroredPropertyMappingPolicy mirror = policy as IMirroredPropertyMappingPolicy;
			if ( mirror != null )
			{
				return new PropertyMappingPolicyInjection( SourceType, mirror.CreateMirror() );
			}
			throw new InvalidOperationException( string.Format( "Type '{0}' does not implement IMirroredPropertyMappingPolicy.", policy.GetType().FullName ) );
		}
	}
}